package com.cy.jt.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @author 小李
 * @version 1.0
 * @date 2021/9/19 9:05
 */
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    /*定义密码加密匹配器对象*/
    @Bean
    public BCryptPasswordEncoder passwordEncoder(){
        return new BCryptPasswordEncoder();
    }
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        //super.configure(http);
        //关闭跨域攻击
        http.csrf().disable();
        //设置认证登录页面
        http.formLogin().loginPage("/login.html");
        //设置认证规则（那些资源必须登录后才能访问，那些资源可以直接访问）
        http.authorizeRequests()
                .antMatchers("/login.html").permitAll()
                .anyRequest().authenticated();
    }
}
